package hot100.logos1To10;

import java.util.*;

/**
 * @author logos
 * date 2025/7/9 11:29
 * @version v1.0
 * @Package hot100
 */
public class logos2 {

    /**
     * 2.字母异位词分组
     * https://leetcode.cn/problems/group-anagrams/description/?envType=study-plan-v2&envId=top-100-liked
     */
    class Solution {
        public List<List<String>> groupAnagrams(String[] strs) {
            HashMap<String, List<String>> map = new HashMap<>();
            for (String str : strs) {
                char[] strArr = str.toCharArray();
                Arrays.sort(strArr);
                String key = Arrays.toString(strArr);
                List<String> tmp = map.getOrDefault(key, new ArrayList<>());
                tmp.add(str);
                map.put(key, tmp);
            }
            return new ArrayList<>(map.values());
        }
    }
}
